
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region CustomItem Model -(by fangyifeng at 2007-09-14 12:24:02)

	/// <summary>
	/// CustomItem object'CustomItem'.
	/// </summary>
	[Serializable]
	public class CustomItem : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected string _name;
		protected short _forceSelect;
		protected string _systemCondition;
		protected string _memo;
		protected CustomItemType _customItemType;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public CustomItem() { }

		public CustomItem( string name, short forceSelect, string systemCondition, string memo, CustomItemType customItemType )
		{
			this._name = name;
			this._forceSelect = forceSelect;
			this._systemCondition = systemCondition;
			this._memo = memo;
			this._customItemType = customItemType;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual string Name
		{
			get { return _name; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Name", value, value.ToString());
				_name = value;
			}
		}

		public virtual short ForceSelect
		{
			get { return _forceSelect; }
			set { _forceSelect = value; }
		}

		public virtual string SystemCondition
		{
			get { return _systemCondition; }
			set
			{
				if ( value != null && value.Length > 3800)
					throw new ArgumentOutOfRangeException("Invalid value for SystemCondition", value, value.ToString());
				_systemCondition = value;
			}
		}

		public virtual string Memo
		{
			get { return _memo; }
			set
			{
				if ( value != null && value.Length > 1000)
					throw new ArgumentOutOfRangeException("Invalid value for Memo", value, value.ToString());
				_memo = value;
			}
		}

		public virtual CustomItemType CustomItemType
		{
			get { return _customItemType; }
			set { _customItemType = value; }
		}

		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is CustomItem))
				throw new InvalidCastException("This object is not of type CustomItem");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((CustomItem)obj).Id);
					break;
				case "Name":
					relativeValue = this.Name.CompareTo(((CustomItem)obj).Name);
					break;
				case "ForceSelect":
					relativeValue = this.ForceSelect.CompareTo(((CustomItem)obj).ForceSelect);
					break;
				case "SystemCondition":
					relativeValue = this.SystemCondition.CompareTo(((CustomItem)obj).SystemCondition);
					break;
				case "Memo":
					relativeValue = (this.Memo != null) ? this.Memo.CompareTo(((CustomItem)obj).Memo) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (CustomItem.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
